home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 November / PCWNOV08.iso / Software / Freeware / Adobe Media Player 1.1 / adobe_media_player.air / AMP.swf / scripts / mx / controls / MenuBar.as < prev    next >
Encoding:
Text File  |  2008-07-17  |  36.7 KB  |  1,133 lines

  1. package mx.controls
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.Event;
  5.    import flash.events.FocusEvent;
  6.    import flash.events.KeyboardEvent;
  7.    import flash.events.MouseEvent;
  8.    import flash.geom.Point;
  9.    import flash.geom.Rectangle;
  10.    import flash.ui.Keyboard;
  11.    import flash.xml.XMLNode;
  12.    import mx.collections.ArrayCollection;
  13.    import mx.collections.ICollectionView;
  14.    import mx.collections.XMLListCollection;
  15.    import mx.collections.errors.ItemPendingError;
  16.    import mx.containers.ApplicationControlBar;
  17.    import mx.controls.menuClasses.IMenuBarItemRenderer;
  18.    import mx.controls.menuClasses.IMenuDataDescriptor;
  19.    import mx.controls.menuClasses.MenuBarItem;
  20.    import mx.controls.treeClasses.DefaultDataDescriptor;
  21.    import mx.core.ClassFactory;
  22.    import mx.core.EventPriority;
  23.    import mx.core.FlexVersion;
  24.    import mx.core.IFactory;
  25.    import mx.core.IFlexDisplayObject;
  26.    import mx.core.IUIComponent;
  27.    import mx.core.UIComponent;
  28.    import mx.core.UIComponentGlobals;
  29.    import mx.core.mx_internal;
  30.    import mx.events.CollectionEvent;
  31.    import mx.events.CollectionEventKind;
  32.    import mx.events.FlexEvent;
  33.    import mx.events.MenuEvent;
  34.    import mx.managers.IFocusManagerComponent;
  35.    import mx.managers.ISystemManager;
  36.    import mx.styles.CSSStyleDeclaration;
  37.    import mx.styles.ISimpleStyleClient;
  38.    import mx.styles.StyleManager;
  39.    import mx.styles.StyleProxy;
  40.    
  41.    use namespace mx_internal;
  42.    
  43.    public class MenuBar extends UIComponent implements IFocusManagerComponent
  44.    {
  45.       mx_internal static var createAccessibilityImplementation:Function;
  46.       
  47.       mx_internal static const VERSION:String = "3.0.0.0";
  48.       
  49.       private static const MARGIN_WIDTH:int = 10;
  50.       
  51.       private static var _menuBarItemStyleFilters:Object = null;
  52.       
  53.       private var dataProviderChanged:Boolean = false;
  54.       
  55.       public var menus:Array;
  56.       
  57.       private var _labelField:String = "label";
  58.       
  59.       private var menuBarItemRendererChanged:Boolean = false;
  60.       
  61.       private var _menuBarItemRenderer:IFactory;
  62.       
  63.       private var openMenuIndex:int = -1;
  64.       
  65.       public var menuBarItems:Array;
  66.       
  67.       private var _iconField:String = "icon";
  68.       
  69.       private var background:IFlexDisplayObject;
  70.       
  71.       mx_internal var showRootChanged:Boolean = false;
  72.       
  73.       private var inKeyDown:Boolean = false;
  74.       
  75.       private var isInsideACB:Boolean = false;
  76.       
  77.       mx_internal var _hasRoot:Boolean = false;
  78.       
  79.       mx_internal var _showRoot:Boolean = true;
  80.       
  81.       private var supposedToLoseFocus:Boolean = false;
  82.       
  83.       mx_internal var _dataDescriptor:IMenuDataDescriptor;
  84.       
  85.       mx_internal var _rootModel:ICollectionView;
  86.       
  87.       public var labelFunction:Function;
  88.       
  89.       private var iconFieldChanged:Boolean = false;
  90.       
  91.       private var isDown:Boolean;
  92.       
  93.       public function MenuBar()
  94.       {
  95.          mx_internal::_dataDescriptor = new DefaultDataDescriptor();
  96.          menuBarItems = [];
  97.          menus = [];
  98.          super();
  99.          menuBarItemRenderer = new ClassFactory(MenuBarItem);
  100.          tabChildren = false;
  101.       }
  102.       
  103.       [Bindable("iconFieldChanged")]
  104.       public function get iconField() : String
  105.       {
  106.          return _iconField;
  107.       }
  108.       
  109.       override public function set enabled(param1:Boolean) : void
  110.       {
  111.          var _loc2_:int = 0;
  112.          var _loc3_:int = 0;
  113.          super.enabled = param1;
  114.          if(menuBarItems)
  115.          {
  116.             _loc2_ = int(menuBarItems.length);
  117.             _loc3_ = 0;
  118.             while(_loc3_ < _loc2_)
  119.             {
  120.                menuBarItems[_loc3_].enabled = param1;
  121.                _loc3_++;
  122.             }
  123.          }
  124.       }
  125.       
  126.       public function get showRoot() : Boolean
  127.       {
  128.          return mx_internal::_showRoot;
  129.       }
  130.       
  131.       override public function set showInAutomationHierarchy(param1:Boolean) : void
  132.       {
  133.       }
  134.       
  135.       private function removeAll() : void
  136.       {
  137.          var _loc1_:IMenuBarItemRenderer = null;
  138.          if(dataProviderChanged)
  139.          {
  140.             commitProperties();
  141.          }
  142.          while(menuBarItems.length > 0)
  143.          {
  144.             _loc1_ = menuBarItems[0];
  145.             removeChild(DisplayObject(_loc1_));
  146.             menuBarItems.splice(0,1);
  147.          }
  148.          menus = [];
  149.          invalidateSize();
  150.          invalidateDisplayList();
  151.       }
  152.       
  153.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  154.       {
  155.          var _loc9_:IMenuBarItemRenderer = null;
  156.          super.updateDisplayList(param1,param2);
  157.          var _loc3_:Number = MARGIN_WIDTH;
  158.          var _loc4_:Number = 0;
  159.          var _loc5_:int = int(menuBarItems.length);
  160.          var _loc6_:Boolean = false;
  161.          var _loc7_:Boolean = param1 == 0 || param2 == 0;
  162.          var _loc8_:int = 0;
  163.          while(_loc8_ < _loc5_)
  164.          {
  165.             _loc9_ = menuBarItems[_loc8_];
  166.             _loc9_.setActualSize(_loc9_.getExplicitOrMeasuredWidth(),param2);
  167.             _loc9_.visible = !_loc7_;
  168.             _loc3_ = _loc9_.x = _loc3_ + _loc4_;
  169.             _loc4_ = Number(_loc9_.width);
  170.             if(!_loc7_ && (_loc9_.getExplicitOrMeasuredHeight() > param2 || _loc3_ + _loc4_ > param1))
  171.             {
  172.                _loc6_ = true;
  173.             }
  174.             _loc8_++;
  175.          }
  176.          if(background)
  177.          {
  178.             background.setActualSize(param1,param2);
  179.             background.visible = !_loc7_;
  180.          }
  181.          scrollRect = _loc6_ ? new Rectangle(0,0,param1,param2) : null;
  182.       }
  183.       
  184.       override public function get baselinePosition() : Number
  185.       {
  186.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  187.          {
  188.             return super.baselinePosition;
  189.          }
  190.          if(!mx_internal::validateBaselinePosition())
  191.          {
  192.             return NaN;
  193.          }
  194.          if(menuBarItems.length == 0)
  195.          {
  196.             return super.baselinePosition;
  197.          }
  198.          var _loc1_:IUIComponent = menuBarItems[0] as IUIComponent;
  199.          if(!_loc1_)
  200.          {
  201.             return super.baselinePosition;
  202.          }
  203.          validateNow();
  204.          return _loc1_.y + _loc1_.baselinePosition;
  205.       }
  206.       
  207.       protected function get menuBarItemStyleFilters() : Object
  208.       {
  209.          return _menuBarItemStyleFilters;
  210.       }
  211.       
  212.       public function set iconField(param1:String) : void
  213.       {
  214.          if(_iconField != param1)
  215.          {
  216.             iconFieldChanged = true;
  217.             _iconField = param1;
  218.             invalidateProperties();
  219.             dispatchEvent(new Event("iconFieldChanged"));
  220.          }
  221.       }
  222.       
  223.       public function set menuBarItemRenderer(param1:IFactory) : void
  224.       {
  225.          if(_menuBarItemRenderer != param1)
  226.          {
  227.             _menuBarItemRenderer = param1;
  228.             menuBarItemRendererChanged = true;
  229.             invalidateProperties();
  230.             dispatchEvent(new Event("menuBarItemRendererChanged"));
  231.          }
  232.       }
  233.       
  234.       public function get hasRoot() : Boolean
  235.       {
  236.          return mx_internal::_hasRoot;
  237.       }
  238.       
  239.       override protected function initializeAccessibility() : void
  240.       {
  241.          if(MenuBar.mx_internal::createAccessibilityImplementation != null)
  242.          {
  243.             MenuBar.mx_internal::createAccessibilityImplementation(this);
  244.          }
  245.       }
  246.       
  247.       public function itemToIcon(param1:Object) : Class
  248.       {
  249.          var iconClass:Class = null;
  250.          var icon:* = undefined;
  251.          var data:Object = param1;
  252.          if(data == null)
  253.          {
  254.             return null;
  255.          }
  256.          if(data is XML)
  257.          {
  258.             try
  259.             {
  260.                if(data[iconField].length() != 0)
  261.                {
  262.                   icon = String(data[iconField]);
  263.                   if(icon != null)
  264.                   {
  265.                      iconClass = Class(systemManager.getDefinitionByName(icon));
  266.                      if(iconClass)
  267.                      {
  268.                         return iconClass;
  269.                      }
  270.                      return document[icon];
  271.                   }
  272.                }
  273.             }
  274.             catch(e:Error)
  275.             {
  276.             }
  277.          }
  278.          else if(data is Object)
  279.          {
  280.             try
  281.             {
  282.                if(data[iconField] != null)
  283.                {
  284.                   if(data[iconField] is Class)
  285.                   {
  286.                      return data[iconField];
  287.                   }
  288.                   if(data[iconField] is String)
  289.                   {
  290.                      iconClass = Class(systemManager.getDefinitionByName(data[iconField]));
  291.                      if(iconClass)
  292.                      {
  293.                         return iconClass;
  294.                      }
  295.                      return document[data[iconField]];
  296.                   }
  297.                }
  298.             }
  299.             catch(e:Error)
  300.             {
  301.             }
  302.          }
  303.          return null;
  304.       }
  305.       
  306.       private function addMenuAt(param1:int, param2:Object, param3:Object = null) : void
  307.       {
  308.          var _loc4_:Menu = null;
  309.          var _loc5_:Object = null;
  310.          if(!dataProvider)
  311.          {
  312.             dataProvider = {};
  313.          }
  314.          var _loc6_:Object = param2;
  315.          insertMenuBarItem(param1,_loc5_);
  316.       }
  317.       
  318.       override protected function createChildren() : void
  319.       {
  320.          super.createChildren();
  321.          var _loc1_:Object = parent;
  322.          while(_loc1_)
  323.          {
  324.             if(_loc1_ is ApplicationControlBar)
  325.             {
  326.                isInsideACB = true;
  327.                break;
  328.             }
  329.             _loc1_ = _loc1_.parent;
  330.          }
  331.          updateBackground();
  332.       }
  333.       
  334.       override protected function focusOutHandler(param1:FocusEvent) : void
  335.       {
  336.          super.focusOutHandler(param1);
  337.          if(supposedToLoseFocus)
  338.          {
  339.             getMenuAt(openMenuIndex).hide();
  340.          }
  341.          supposedToLoseFocus = false;
  342.       }
  343.       
  344.       public function itemToLabel(param1:Object) : String
  345.       {
  346.          var data:Object = param1;
  347.          if(data == null)
  348.          {
  349.             return " ";
  350.          }
  351.          if(labelFunction != null)
  352.          {
  353.             return labelFunction(data);
  354.          }
  355.          if(data is XML)
  356.          {
  357.             try
  358.             {
  359.                if(data[labelField].length() != 0)
  360.                {
  361.                   data = data[labelField];
  362.                }
  363.             }
  364.             catch(e:Error)
  365.             {
  366.             }
  367.          }
  368.          else if(data is Object)
  369.          {
  370.             try
  371.             {
  372.                if(data[labelField] != null)
  373.                {
  374.                   data = data[labelField];
  375.                }
  376.             }
  377.             catch(e:Error)
  378.             {
  379.             }
  380.          }
  381.          else if(data is String)
  382.          {
  383.             return String(data);
  384.          }
  385.          try
  386.          {
  387.             return data.toString();
  388.          }
  389.          catch(e:Error)
  390.          {
  391.          }
  392.          return " ";
  393.       }
  394.       
  395.       private function mouseOutHandler(param1:MouseEvent) : void
  396.       {
  397.          var _loc5_:MenuEvent = null;
  398.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  399.          var _loc3_:int = _loc2_.menuBarItemIndex;
  400.          var _loc4_:Menu = getMenuAt(_loc3_);
  401.          if(Boolean(_loc2_.enabled) && openMenuIndex != _loc3_)
  402.          {
  403.             menuBarItems[_loc3_].menuBarItemState = "itemUpSkin";
  404.          }
  405.          if(Boolean(_loc2_.data) && _loc4_.dataDescriptor.getType(_loc2_.data) != "separator")
  406.          {
  407.             _loc5_ = new MenuEvent(MenuEvent.ITEM_ROLL_OUT);
  408.             _loc5_.index = _loc3_;
  409.             _loc5_.menuBar = this;
  410.             _loc5_.label = itemToLabel(_loc2_.data);
  411.             _loc5_.item = _loc2_.data;
  412.             _loc5_.itemRenderer = _loc2_;
  413.             dispatchEvent(_loc5_);
  414.          }
  415.       }
  416.       
  417.       private function collectionChangeHandler(param1:Event) : void
  418.       {
  419.          var _loc2_:CollectionEvent = null;
  420.          if(param1 is CollectionEvent)
  421.          {
  422.             _loc2_ = CollectionEvent(param1);
  423.             if(_loc2_.kind == CollectionEventKind.ADD)
  424.             {
  425.                dataProviderChanged = true;
  426.                invalidateProperties();
  427.             }
  428.             else if(_loc2_.kind == CollectionEventKind.REMOVE)
  429.             {
  430.                dataProviderChanged = true;
  431.                invalidateProperties();
  432.             }
  433.             else if(_loc2_.kind == CollectionEventKind.REFRESH)
  434.             {
  435.                dataProviderChanged = true;
  436.                dataProvider = dataProvider;
  437.                invalidateProperties();
  438.                invalidateSize();
  439.             }
  440.             else if(_loc2_.kind == CollectionEventKind.RESET)
  441.             {
  442.                dataProviderChanged = true;
  443.                invalidateProperties();
  444.                invalidateSize();
  445.             }
  446.             else if(_loc2_.kind == CollectionEventKind.UPDATE)
  447.             {
  448.                if(openMenuIndex == -1)
  449.                {
  450.                   dataProviderChanged = true;
  451.                   invalidateProperties();
  452.                }
  453.             }
  454.          }
  455.          invalidateDisplayList();
  456.       }
  457.       
  458.       override public function notifyStyleChangeInChildren(param1:String, param2:Boolean) : void
  459.       {
  460.          super.notifyStyleChangeInChildren(param1,param2);
  461.          var _loc3_:int = int(menuBarItems.length);
  462.          var _loc4_:int = 0;
  463.          while(_loc4_ < _loc3_)
  464.          {
  465.             getMenuAt(_loc4_).notifyStyleChangeInChildren(param1,param2);
  466.             _loc4_++;
  467.          }
  468.       }
  469.       
  470.       private function mouseUpHandler(param1:MouseEvent) : void
  471.       {
  472.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  473.          var _loc3_:int = _loc2_.menuBarItemIndex;
  474.          if(Boolean(_loc2_.enabled) && !isDown)
  475.          {
  476.             getMenuAt(_loc3_).mx_internal::hideAllMenus();
  477.             _loc2_.menuBarItemState = "itemOverSkin";
  478.          }
  479.       }
  480.       
  481.       private function mouseDownHandler(param1:MouseEvent) : void
  482.       {
  483.          var _loc5_:ICollectionView = null;
  484.          var _loc6_:MenuEvent = null;
  485.          var _loc7_:MenuEvent = null;
  486.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  487.          var _loc3_:int = _loc2_.menuBarItemIndex;
  488.          var _loc4_:Menu = getMenuAt(_loc3_);
  489.          if(_loc2_.enabled)
  490.          {
  491.             _loc2_.menuBarItemState = "itemDownSkin";
  492.             if(!isDown)
  493.             {
  494.                _loc4_.mx_internal::supposedToLoseFocus = true;
  495.                _loc5_ = ICollectionView(_loc4_.dataProvider);
  496.                if(_loc4_.dataDescriptor.isBranch(_loc2_.data,_loc2_.data) && _loc4_.dataDescriptor.hasChildren(_loc2_.data,_loc2_.data))
  497.                {
  498.                   showMenu(_loc3_);
  499.                }
  500.                else if(_loc4_)
  501.                {
  502.                   selectedIndex = _loc3_;
  503.                   _loc6_ = new MenuEvent(MenuEvent.MENU_SHOW);
  504.                   _loc6_.menuBar = this;
  505.                   _loc6_.menu = _loc4_;
  506.                   dispatchEvent(_loc6_);
  507.                }
  508.                isDown = true;
  509.             }
  510.             else
  511.             {
  512.                isDown = false;
  513.             }
  514.             if(_loc4_.dataDescriptor.getType(_loc2_.data) != "separator")
  515.             {
  516.                _loc7_ = new MenuEvent(MenuEvent.CHANGE);
  517.                _loc7_.index = _loc3_;
  518.                _loc7_.menuBar = this;
  519.                _loc7_.label = itemToLabel(_loc2_.data);
  520.                _loc7_.item = _loc2_.data;
  521.                _loc7_.itemRenderer = _loc2_;
  522.                dispatchEvent(_loc7_);
  523.             }
  524.          }
  525.       }
  526.       
  527.       public function get dataDescriptor() : IMenuDataDescriptor
  528.       {
  529.          return IMenuDataDescriptor(mx_internal::_dataDescriptor);
  530.       }
  531.       
  532.       [Bindable("collectionChange")]
  533.       public function get dataProvider() : Object
  534.       {
  535.          if(mx_internal::_rootModel)
  536.          {
  537.             return mx_internal::_rootModel;
  538.          }
  539.          return null;
  540.       }
  541.       
  542.       private function showMenu(param1:Number) : void
  543.       {
  544.          selectedIndex = param1;
  545.          var _loc2_:IMenuBarItemRenderer = menuBarItems[param1];
  546.          var _loc3_:Menu = getMenuAt(param1);
  547.          var _loc4_:ISystemManager = systemManager;
  548.          var _loc5_:Rectangle = _loc4_.screen;
  549.          UIComponentGlobals.mx_internal::layoutManager.validateClient(_loc3_,true);
  550.          var _loc6_:Point = new Point(0,0);
  551.          _loc6_ = DisplayObject(_loc2_).localToGlobal(_loc6_);
  552.          if(_loc6_.y + _loc2_.height + 1 + _loc3_.getExplicitOrMeasuredHeight() > _loc5_.height + _loc5_.y)
  553.          {
  554.             _loc6_.y -= _loc3_.getExplicitOrMeasuredHeight();
  555.          }
  556.          else
  557.          {
  558.             _loc6_.y += _loc2_.height + 1;
  559.          }
  560.          if(_loc6_.x + _loc3_.getExplicitOrMeasuredWidth() > _loc5_.width + _loc5_.x)
  561.          {
  562.             _loc6_.x = _loc5_.x + _loc5_.width - _loc3_.getExplicitOrMeasuredWidth();
  563.          }
  564.          _loc6_ = DisplayObject(_loc4_.topLevelSystemManager).globalToLocal(_loc6_);
  565.          if(isInsideACB)
  566.          {
  567.             _loc6_.y += 2;
  568.          }
  569.          _loc3_.show(_loc6_.x,_loc6_.y);
  570.       }
  571.       
  572.       [Bindable("menuBarItemRendererChanged")]
  573.       public function get menuBarItemRenderer() : IFactory
  574.       {
  575.          return _menuBarItemRenderer;
  576.       }
  577.       
  578.       public function getMenuAt(param1:int) : Menu
  579.       {
  580.          var _loc5_:Object = null;
  581.          var _loc6_:CSSStyleDeclaration = null;
  582.          if(dataProviderChanged)
  583.          {
  584.             commitProperties();
  585.          }
  586.          var _loc2_:IMenuBarItemRenderer = menuBarItems[param1];
  587.          var _loc3_:Object = _loc2_.data;
  588.          var _loc4_:Menu = menus[param1];
  589.          if(_loc4_ == null)
  590.          {
  591.             _loc4_ = new Menu();
  592.             _loc4_.showRoot = false;
  593.             if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  594.             {
  595.                _loc4_.styleName = this;
  596.             }
  597.             _loc5_ = getStyle("menuStyleName");
  598.             if(_loc5_)
  599.             {
  600.                if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  601.                {
  602.                   _loc6_ = StyleManager.getStyleDeclaration("." + _loc5_);
  603.                   if(_loc6_)
  604.                   {
  605.                      _loc4_.styleDeclaration = _loc6_;
  606.                   }
  607.                }
  608.                else
  609.                {
  610.                   _loc4_.styleName = _loc5_;
  611.                }
  612.             }
  613.             _loc4_.mx_internal::sourceMenuBar = this;
  614.             _loc4_.owner = this;
  615.             _loc4_.addEventListener("menuHide",eventHandler);
  616.             _loc4_.addEventListener("itemRollOver",eventHandler);
  617.             _loc4_.addEventListener("itemRollOut",eventHandler);
  618.             _loc4_.addEventListener("menuShow",eventHandler);
  619.             _loc4_.addEventListener("itemClick",eventHandler);
  620.             _loc4_.addEventListener("change",eventHandler);
  621.             _loc4_.iconField = _iconField;
  622.             _loc4_.labelField = _labelField;
  623.             _loc4_.labelFunction = labelFunction;
  624.             _loc4_.dataDescriptor = mx_internal::_dataDescriptor;
  625.             _loc4_.invalidateSize();
  626.             menus[param1] = _loc4_;
  627.             _loc4_.mx_internal::sourceMenuBarItem = _loc2_;
  628.             Menu.popUpMenu(_loc4_,this,_loc3_);
  629.          }
  630.          return _loc4_;
  631.       }
  632.       
  633.       public function set labelField(param1:String) : void
  634.       {
  635.          if(_labelField != param1)
  636.          {
  637.             _labelField = param1;
  638.             dispatchEvent(new Event("labelFieldChanged"));
  639.          }
  640.       }
  641.       
  642.       override protected function commitProperties() : void
  643.       {
  644.          var i:int = 0;
  645.          var tmpCollection:ICollectionView = null;
  646.          var rootItem:* = undefined;
  647.          var collectionLength:int = 0;
  648.          if(mx_internal::showRootChanged)
  649.          {
  650.             if(!mx_internal::_hasRoot)
  651.             {
  652.                mx_internal::showRootChanged = false;
  653.             }
  654.          }
  655.          if(dataProviderChanged || mx_internal::showRootChanged)
  656.          {
  657.             dataProviderChanged = false;
  658.             mx_internal::showRootChanged = false;
  659.             if(mx_internal::_rootModel && !mx_internal::_showRoot && mx_internal::_hasRoot)
  660.             {
  661.                rootItem = mx_internal::_rootModel.createCursor().current;
  662.                if(rootItem != null && mx_internal::_dataDescriptor.isBranch(rootItem,mx_internal::_rootModel) && mx_internal::_dataDescriptor.hasChildren(rootItem,mx_internal::_rootModel))
  663.                {
  664.                   tmpCollection = mx_internal::_dataDescriptor.getChildren(rootItem,mx_internal::_rootModel);
  665.                }
  666.             }
  667.             removeAll();
  668.             if(mx_internal::_rootModel)
  669.             {
  670.                if(!tmpCollection)
  671.                {
  672.                   tmpCollection = mx_internal::_rootModel;
  673.                }
  674.                tmpCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,EventPriority.DEFAULT_HANDLER,true);
  675.                collectionLength = tmpCollection.length;
  676.                i = 0;
  677.                while(i < collectionLength)
  678.                {
  679.                   try
  680.                   {
  681.                      insertMenuBarItem(i,tmpCollection[i]);
  682.                   }
  683.                   catch(e:ItemPendingError)
  684.                   {
  685.                   }
  686.                   i++;
  687.                }
  688.             }
  689.          }
  690.          if(iconFieldChanged || menuBarItemRendererChanged)
  691.          {
  692.             iconFieldChanged = false;
  693.             menuBarItemRendererChanged = false;
  694.             removeAll();
  695.             if(mx_internal::_rootModel)
  696.             {
  697.                if(!tmpCollection)
  698.                {
  699.                   tmpCollection = mx_internal::_rootModel;
  700.                }
  701.                i = 0;
  702.                while(i < tmpCollection.length)
  703.                {
  704.                   try
  705.                   {
  706.                      insertMenuBarItem(i,tmpCollection[i]);
  707.                   }
  708.                   catch(e:ItemPendingError)
  709.                   {
  710.                   }
  711.                   i++;
  712.                }
  713.             }
  714.          }
  715.          super.commitProperties();
  716.       }
  717.       
  718.       override public function styleChanged(param1:String) : void
  719.       {
  720.          var _loc2_:int = 0;
  721.          var _loc4_:String = null;
  722.          var _loc5_:Menu = null;
  723.          var _loc6_:CSSStyleDeclaration = null;
  724.          super.styleChanged(param1);
  725.          var _loc3_:int = int(menuBarItems.length);
  726.          _loc2_ = 0;
  727.          while(_loc2_ < _loc3_)
  728.          {
  729.             getMenuAt(_loc2_).styleChanged(param1);
  730.             _loc2_++;
  731.          }
  732.          if(!param1 || param1 == "" || param1 == "backgroundSkin")
  733.          {
  734.             updateBackground();
  735.          }
  736.          if(param1 == null || param1 == "styleName" || param1 == "menuStyleName")
  737.          {
  738.             _loc4_ = getStyle("menuStyleName");
  739.             if(_loc4_)
  740.             {
  741.                if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  742.                {
  743.                   _loc6_ = StyleManager.getStyleDeclaration("." + _loc4_);
  744.                   if(_loc6_)
  745.                   {
  746.                      _loc2_ = 0;
  747.                      while(_loc2_ < menus.length)
  748.                      {
  749.                         _loc5_ = menus[_loc2_];
  750.                         _loc5_.styleDeclaration = _loc6_;
  751.                         _loc5_.regenerateStyleCache(true);
  752.                         _loc2_++;
  753.                      }
  754.                   }
  755.                }
  756.                else
  757.                {
  758.                   _loc2_ = 0;
  759.                   while(_loc2_ < menus.length)
  760.                   {
  761.                      _loc5_ = menus[_loc2_];
  762.                      _loc5_.styleName = _loc4_;
  763.                      _loc2_++;
  764.                   }
  765.                }
  766.             }
  767.          }
  768.       }
  769.       
  770.       private function removeMenuBarItemAt(param1:int) : void
  771.       {
  772.          if(dataProviderChanged)
  773.          {
  774.             commitProperties();
  775.          }
  776.          var _loc2_:IMenuBarItemRenderer = menuBarItems[param1];
  777.          if(_loc2_)
  778.          {
  779.             removeChild(DisplayObject(_loc2_));
  780.             menuBarItems.splice(param1,1);
  781.             invalidateSize();
  782.             invalidateDisplayList();
  783.          }
  784.       }
  785.       
  786.       protected function updateBackground() : void
  787.       {
  788.          var _loc1_:Class = null;
  789.          if(isInsideACB)
  790.          {
  791.             setStyle("translucent",true);
  792.          }
  793.          else
  794.          {
  795.             if(background)
  796.             {
  797.                removeChild(DisplayObject(background));
  798.                background = null;
  799.             }
  800.             _loc1_ = getStyle("backgroundSkin");
  801.             background = new _loc1_();
  802.             if(background is ISimpleStyleClient)
  803.             {
  804.                ISimpleStyleClient(background).styleName = this;
  805.             }
  806.             addChildAt(DisplayObject(background),0);
  807.          }
  808.       }
  809.       
  810.       override protected function measure() : void
  811.       {
  812.          var _loc2_:int = 0;
  813.          super.measure();
  814.          var _loc1_:int = int(menuBarItems.length);
  815.          measuredWidth = 0;
  816.          measuredHeight = DEFAULT_MEASURED_MIN_HEIGHT;
  817.          _loc2_ = 0;
  818.          while(_loc2_ < _loc1_)
  819.          {
  820.             measuredWidth += menuBarItems[_loc2_].getExplicitOrMeasuredWidth();
  821.             measuredHeight = Math.max(measuredHeight,menuBarItems[_loc2_].getExplicitOrMeasuredHeight());
  822.             _loc2_++;
  823.          }
  824.          if(_loc1_ > 0)
  825.          {
  826.             measuredWidth += 2 * MARGIN_WIDTH;
  827.          }
  828.          else
  829.          {
  830.             measuredWidth = DEFAULT_MEASURED_MIN_WIDTH;
  831.          }
  832.          measuredMinWidth = measuredWidth;
  833.          measuredMinHeight = measuredHeight;
  834.       }
  835.       
  836.       override protected function keyDownHandler(param1:KeyboardEvent) : void
  837.       {
  838.          var _loc3_:int = 0;
  839.          var _loc4_:Boolean = false;
  840.          var _loc5_:int = 0;
  841.          var _loc6_:Menu = null;
  842.          var _loc7_:ICollectionView = null;
  843.          var _loc8_:IMenuBarItemRenderer = null;
  844.          var _loc2_:int = int(menuBarItems.length);
  845.          if(param1.keyCode == Keyboard.RIGHT || param1.keyCode == Keyboard.LEFT)
  846.          {
  847.             inKeyDown = true;
  848.             _loc3_ = openMenuIndex;
  849.             _loc4_ = false;
  850.             _loc5_ = 0;
  851.             while(!_loc4_ && _loc5_ < _loc2_)
  852.             {
  853.                _loc5_++;
  854.                _loc3_ = param1.keyCode == Keyboard.RIGHT ? _loc3_ + 1 : _loc3_ - 1;
  855.                if(_loc3_ >= _loc2_)
  856.                {
  857.                   _loc3_ = 0;
  858.                }
  859.                else if(_loc3_ < 0)
  860.                {
  861.                   _loc3_ = _loc2_ - 1;
  862.                }
  863.                if(menuBarItems[_loc3_].enabled)
  864.                {
  865.                   _loc4_ = true;
  866.                }
  867.             }
  868.             if(_loc5_ <= _loc2_ && _loc4_)
  869.             {
  870.                menuBarItems[_loc3_].dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
  871.             }
  872.             param1.stopPropagation();
  873.          }
  874.          if(param1.keyCode == Keyboard.DOWN)
  875.          {
  876.             if(openMenuIndex != -1)
  877.             {
  878.                _loc6_ = getMenuAt(openMenuIndex);
  879.                _loc6_.selectedIndex = 0;
  880.                supposedToLoseFocus = true;
  881.                _loc7_ = ICollectionView(_loc6_.dataProvider);
  882.                _loc8_ = _loc6_.mx_internal::sourceMenuBarItem;
  883.                if(_loc6_.dataDescriptor.isBranch(_loc8_.data,_loc8_.data) && _loc6_.dataDescriptor.hasChildren(_loc8_.data,_loc8_.data))
  884.                {
  885.                   _loc6_.setFocus();
  886.                }
  887.             }
  888.             param1.stopPropagation();
  889.          }
  890.          if(param1.keyCode == Keyboard.ENTER || param1.keyCode == Keyboard.ESCAPE)
  891.          {
  892.             if(openMenuIndex != -1)
  893.             {
  894.                getMenuAt(openMenuIndex).hide();
  895.             }
  896.             param1.stopPropagation();
  897.          }
  898.       }
  899.       
  900.       [Bindable("labelFieldChanged")]
  901.       public function get labelField() : String
  902.       {
  903.          return _labelField;
  904.       }
  905.       
  906.       public function set selectedIndex(param1:int) : void
  907.       {
  908.          openMenuIndex = param1;
  909.          dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  910.       }
  911.       
  912.       private function mouseOverHandler(param1:MouseEvent) : void
  913.       {
  914.          var _loc6_:MenuEvent = null;
  915.          var _loc7_:Number = NaN;
  916.          var _loc8_:ICollectionView = null;
  917.          var _loc9_:IMenuBarItemRenderer = null;
  918.          var _loc10_:Menu = null;
  919.          var _loc2_:IMenuBarItemRenderer = IMenuBarItemRenderer(param1.target);
  920.          var _loc3_:int = _loc2_.menuBarItemIndex;
  921.          var _loc4_:Boolean = false;
  922.          var _loc5_:Menu = getMenuAt(_loc3_);
  923.          if(_loc2_.enabled)
  924.          {
  925.             if(openMenuIndex != -1 || inKeyDown)
  926.             {
  927.                _loc7_ = openMenuIndex;
  928.                if(_loc7_ != _loc3_)
  929.                {
  930.                   isDown = false;
  931.                   if(_loc7_ != -1)
  932.                   {
  933.                      _loc9_ = menuBarItems[_loc7_];
  934.                      _loc9_.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP));
  935.                      _loc9_.menuBarItemState = "itemUpSkin";
  936.                      _loc6_ = new MenuEvent(MenuEvent.ITEM_ROLL_OUT);
  937.                      _loc6_.menuBar = this;
  938.                      _loc6_.index = _loc7_;
  939.                      _loc6_.label = itemToLabel(_loc9_.data);
  940.                      _loc6_.item = _loc9_.data;
  941.                      _loc6_.itemRenderer = _loc9_;
  942.                      dispatchEvent(_loc6_);
  943.                   }
  944.                   _loc2_.menuBarItemState = "itemDownSkin";
  945.                   _loc8_ = ICollectionView(_loc5_.dataProvider);
  946.                   if(_loc5_.dataDescriptor.isBranch(_loc2_.data,_loc2_.data) && _loc5_.dataDescriptor.hasChildren(_loc2_.data,_loc2_.data))
  947.                   {
  948.                      showMenu(_loc3_);
  949.                   }
  950.                   else if(_loc5_)
  951.                   {
  952.                      selectedIndex = _loc3_;
  953.                      _loc6_ = new MenuEvent(MenuEvent.MENU_SHOW);
  954.                      _loc6_.menuBar = this;
  955.                      _loc6_.menu = _loc5_;
  956.                      dispatchEvent(_loc6_);
  957.                      _loc2_.menuBarItemState = "itemOverSkin";
  958.                   }
  959.                   isDown = true;
  960.                   if(_loc5_.dataDescriptor.getType(_loc2_.data) != "separator")
  961.                   {
  962.                      _loc4_ = true;
  963.                      _loc6_ = new MenuEvent(MenuEvent.CHANGE);
  964.                      _loc6_.index = _loc3_;
  965.                      _loc6_.menuBar = this;
  966.                      _loc6_.label = itemToLabel(_loc2_.data);
  967.                      _loc6_.item = _loc2_.data;
  968.                      _loc6_.itemRenderer = _loc2_;
  969.                      dispatchEvent(_loc6_);
  970.                   }
  971.                }
  972.                else
  973.                {
  974.                   _loc10_ = getMenuAt(_loc3_);
  975.                   _loc10_.mx_internal::deleteDependentSubMenus();
  976.                   _loc10_.setFocus();
  977.                }
  978.             }
  979.             else
  980.             {
  981.                _loc2_.menuBarItemState = "itemOverSkin";
  982.                isDown = false;
  983.                if(_loc5_.dataDescriptor.getType(_loc2_.data) != "separator")
  984.                {
  985.                   _loc4_ = true;
  986.                }
  987.             }
  988.             inKeyDown = false;
  989.             if(_loc4_)
  990.             {
  991.                _loc6_ = new MenuEvent(MenuEvent.ITEM_ROLL_OVER);
  992.                _loc6_.index = _loc3_;
  993.                _loc6_.menuBar = this;
  994.                _loc6_.label = itemToLabel(_loc2_.data);
  995.                _loc6_.item = _loc2_.data;
  996.                _loc6_.itemRenderer = _loc2_;
  997.                dispatchEvent(_loc6_);
  998.             }
  999.          }
  1000.       }
  1001.       
  1002.       public function set dataDescriptor(param1:IMenuDataDescriptor) : void
  1003.       {
  1004.          mx_internal::_dataDescriptor = param1;
  1005.          menus = [];
  1006.       }
  1007.       
  1008.       private function insertMenuBarItem(param1:int, param2:Object) : void
  1009.       {
  1010.          if(dataProviderChanged)
  1011.          {
  1012.             commitProperties();
  1013.             return;
  1014.          }
  1015.          var _loc3_:IMenuBarItemRenderer = menuBarItemRenderer.newInstance();
  1016.          _loc3_.styleName = new StyleProxy(this,menuBarItemStyleFilters);
  1017.          _loc3_.visible = false;
  1018.          _loc3_.enabled = enabled && mx_internal::_dataDescriptor.isEnabled(param2) != false;
  1019.          _loc3_.data = param2;
  1020.          _loc3_.menuBar = this;
  1021.          _loc3_.menuBarItemIndex = param1;
  1022.          addChild(DisplayObject(_loc3_));
  1023.          menuBarItems.splice(param1,0,_loc3_);
  1024.          invalidateSize();
  1025.          invalidateDisplayList();
  1026.          _loc3_.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
  1027.          _loc3_.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
  1028.          _loc3_.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
  1029.          _loc3_.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
  1030.       }
  1031.       
  1032.       public function set dataProvider(param1:Object) : void
  1033.       {
  1034.          var _loc3_:XMLList = null;
  1035.          var _loc4_:Array = null;
  1036.          if(mx_internal::_rootModel)
  1037.          {
  1038.             mx_internal::_rootModel.removeEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler);
  1039.          }
  1040.          if(typeof param1 == "string")
  1041.          {
  1042.             param1 = new XML(param1);
  1043.          }
  1044.          else if(param1 is XMLNode)
  1045.          {
  1046.             param1 = new XML(XMLNode(param1).toString());
  1047.          }
  1048.          else if(param1 is XMLList)
  1049.          {
  1050.             param1 = new XMLListCollection(param1 as XMLList);
  1051.          }
  1052.          if(param1 is XML)
  1053.          {
  1054.             mx_internal::_hasRoot = true;
  1055.             _loc3_ = new XMLList();
  1056.             _loc3_ += param1;
  1057.             mx_internal::_rootModel = new XMLListCollection(_loc3_);
  1058.          }
  1059.          else if(param1 is ICollectionView)
  1060.          {
  1061.             mx_internal::_rootModel = ICollectionView(param1);
  1062.             if(mx_internal::_rootModel.length == 1)
  1063.             {
  1064.                mx_internal::_hasRoot = true;
  1065.             }
  1066.          }
  1067.          else if(param1 is Array)
  1068.          {
  1069.             mx_internal::_rootModel = new ArrayCollection(param1 as Array);
  1070.          }
  1071.          else if(param1 is Object)
  1072.          {
  1073.             mx_internal::_hasRoot = true;
  1074.             _loc4_ = [];
  1075.             _loc4_.push(param1);
  1076.             mx_internal::_rootModel = new ArrayCollection(_loc4_);
  1077.          }
  1078.          else
  1079.          {
  1080.             mx_internal::_rootModel = new ArrayCollection();
  1081.          }
  1082.          mx_internal::_rootModel.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,0,true);
  1083.          dataProviderChanged = true;
  1084.          invalidateProperties();
  1085.          var _loc2_:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
  1086.          _loc2_.kind = CollectionEventKind.RESET;
  1087.          collectionChangeHandler(_loc2_);
  1088.          dispatchEvent(_loc2_);
  1089.       }
  1090.       
  1091.       [Bindable("valueCommit")]
  1092.       public function get selectedIndex() : int
  1093.       {
  1094.          return openMenuIndex;
  1095.       }
  1096.       
  1097.       override protected function focusInHandler(param1:FocusEvent) : void
  1098.       {
  1099.          super.focusInHandler(param1);
  1100.       }
  1101.       
  1102.       private function eventHandler(param1:Event) : void
  1103.       {
  1104.          var _loc2_:String = null;
  1105.          if(param1 is MenuEvent)
  1106.          {
  1107.             _loc2_ = param1.type;
  1108.             if(param1.type == MenuEvent.MENU_HIDE && MenuEvent(param1).menu == menus[openMenuIndex])
  1109.             {
  1110.                menuBarItems[openMenuIndex].menuBarItemState = "itemUpSkin";
  1111.                openMenuIndex = -1;
  1112.                dispatchEvent(param1 as MenuEvent);
  1113.             }
  1114.             else
  1115.             {
  1116.                dispatchEvent(param1);
  1117.             }
  1118.          }
  1119.       }
  1120.       
  1121.       public function set showRoot(param1:Boolean) : void
  1122.       {
  1123.          if(mx_internal::_showRoot != param1)
  1124.          {
  1125.             mx_internal::showRootChanged = true;
  1126.             mx_internal::_showRoot = param1;
  1127.             invalidateProperties();
  1128.          }
  1129.       }
  1130.    }
  1131. }
  1132.  
  1133.